<template>
   <div class="lgbg">

     <md-field style="margin-top:150px">
       <md-input-item
         title="用户名"
         placeholder="请输入用户名"
         clearable
         v-model="username"
       ></md-input-item>
       <md-input-item
         title="密码"
         type="password"
         placeholder="请输入密码"
         clearable
         v-model="password"
       ></md-input-item>

     </md-field>

     <md-button style="margin-top:30px" @click="agentlogin">登录</md-button>

   </div>

</template>

<script>
import { Toast } from 'mand-mobile'
export default {
  name: 'login',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  created: async function () {
    // 判断store中是否有agent信息 如果没有就要需要登录
    if (!this.$store.state.agent.uid) {

    }
  },
  methods: {
    agentlogin: async function () {
      let res = await this.$api.post('/fx/agentlogin', {
        username: this.username,
        password: this.password
      })
      let {state, data} = res.data

      if (state) {
        this.$router.push({name: 'agent_home', query: { agent_oid: data.openid }})
      } else {
        Toast.failed('登录失败')
      }
    }
  }
}
</script>

<style scoped>
.lgbg{
  height: 100%;
}
</style>
